package com.jash.designpack2;

import android.graphics.Color;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

public class SlidingActivity extends AppCompatActivity implements SlidingPaneLayout.PanelSlideListener {

    private SlidingPaneLayout sliding;
    private DrawerArrowDrawable arrow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sliding);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        sliding = (SlidingPaneLayout) findViewById(R.id.sliding);
        sliding.setSliderFadeColor(0);
        sliding.setPanelSlideListener(this);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        arrow = new DrawerArrowDrawable(this);
        arrow.setColor(Color.WHITE);
        actionBar.setHomeAsUpIndicator(arrow);
    }

    @Override
    public void onPanelSlide(View panel, float slideOffset) {
        ViewCompat.setPivotX(panel, 0);
        ViewCompat.setPivotY(panel, panel.getHeight() / 2);
        ViewCompat.setScaleX(panel, 1 - slideOffset * 0.5f);
        ViewCompat.setScaleY(panel, 1 - slideOffset * 0.5f);
        arrow.setProgress(slideOffset);
    }

    @Override
    public void onPanelOpened(View panel) {

    }

    @Override
    public void onPanelClosed(View panel) {

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                if (sliding.isOpen()) {
                    sliding.closePane();
                } else {
                    sliding.openPane();
                }
                break;
        }
        return true;
    }
}
